package com.hitalkie.teacher.activity;

import android.content.Intent;
import android.os.Bundle;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.hitalkie.teacher.R;

/**
 * Date 07/11/2016
 *
 * @author charliema
 */

public class Input2Activity extends BaseActivity {

    public static final String EXTRA_TITLE = "com.hitalkie.talkie.extra.TITLE";
    public static final String EXTRA_CONTENT = "com.hitalkie.talkie.extra.CONTENT";

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);

        initView();

    }

    private void initView() {
        setContentView(R.layout.view_input_2);
        initTitleBar();
        initForm();
    }

    private void initTitleBar() {
        findViewById(R.id.ivTitleBarLeft).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                getActivity().finish();
            }
        });
        String title = getIntent().getStringExtra(EXTRA_TITLE);
        if (!TextUtils.isEmpty(title)) {
            ((TextView) findViewById(R.id.tvTitleBarCenter)).setText(title);
        }
        findViewById(R.id.tvTitleBarRight).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String content = ((TextView) findViewById(R.id.et)).getText().toString();
                Intent i = new Intent();
                i.putExtra(EXTRA_CONTENT, content);
                setResult(RESULT_OK, i);
                getActivity().finish();
            }
        });
    }

    private void initForm() {
        String content = getIntent().getStringExtra(EXTRA_CONTENT);
        if (!TextUtils.isEmpty(content)) {
            ((TextView) findViewById(R.id.et)).setText(content);
        }
    }
}
